package com.mimosa.common.system.login;

import org.springframework.stereotype.Repository;

import com.mimosa.common.dao.HibernateDao;
import com.mimosa.util.config.Page;

/**
 * 登录信息的DAO类
 * 
 * @filename TLoginDao.java
 * @author ggeagle
 * @date 2013-7-14 下午10:19:57
 */
@Repository
public class TLoginDao extends HibernateDao<TLogin, String> {
	/**
	 * 根据用户对浏览记录进行统计
	 * 
	 * @param page
	 *            分页信息对象
	 * @return
	 */
	public Page<TLogin> staticsByUser(Page<TLogin> page) {
		Long totalCount = this.findUnique("select count(distinct userId) from TLogin");
		if (totalCount == null) {
			totalCount = 0l;
		}
		page.setTotalCount(totalCount.intValue());
		page.setAutoCount(Boolean.FALSE);
		page = this.findPage(page, "select new TLogin(userId, MAX(loginTime) as loginTime, count(*) as numCount) from TLogin GROUP BY userId");
		return page;
	}
}